package com.binyouwei.designpatterns.structural_type.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 宾有为
 * @date 2024/7/12 20:11
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：
 **/
public class CompositeEmployee {
    private String name;
    private String dept;
    private int salary;
    private List<CompositeEmployee> subordinates;

    //构造函数
    public CompositeEmployee(String name,String dept, int sal) {
        this.name = name;
        this.dept = dept;
        this.salary = sal;
        subordinates = new ArrayList<CompositeEmployee>();
    }

    public void add(CompositeEmployee e) {
        subordinates.add(e);
    }

    public void remove(CompositeEmployee e) {
        subordinates.remove(e);
    }

    public List<CompositeEmployee> getSubordinates(){
        return subordinates;
    }

    public String toString(){
        return ("CompositeEmployee :[ Name : "+ name
                +", dept : "+ dept + ", salary :"
                + salary+" ]");
    }
}
